<template>
	<view class="payment">
		<view class="left_scroll">
			<view class="left_title" v-for="(item,index) in fuckMap" :key="index"
				:class="index == indexValue ? 'left_color': ''" @click="ClickIndex(index)">{{item}}</view>
		</view>
		<view class="fuck" v-show='indexValue===0?true:false'>
			<view class="bankmcAll">
				<view class="bankmc">
					<view class="bankmc_title">
						银行账户
					</view>
					<!-- <view class="bank_nr" @tap="getDetail(bankAccount)">
						{{bankAccount}}
					</view> -->
				</view>
				<view class="bankmc">
					<view class="bankmc_title">
						账号名称
					</view>
					<!-- 	<view class="bank_nr" id="bar" @tap="getDetail(accountName)">
						{{accountName}}
					</view> -->
				</view>
				<view class="bankmc">
					<view class="bankmc_title">
						银行名称
					</view>
					<!-- 	<view class="bank_nr" @tap="getDetail(bankName)">
						{{bankName}}
					</view> -->
				</view>
				<p class="ppp">可复制</p>

			</view>
			<view class="bankMcAll">
				<view class="bankmc2">
					<view class="bankmc_title">
						持卡人姓名
					</view>
					<view class="bank_nr">
						<input v-model="CkName" />
					</view>
				</view>
				<view class="bankmc2">
					<view class="bankmc_title">
						银行卡账号
					</view>
					<view class="bank_nr">
						<input v-model="Ckkh" />
					</view>
				</view>
				<view class="bankmc2">
					<view class="bankmc_title">
						申请金额
					</view>
					<view class="bank_nr">
						<input v-model="price" />
					</view>
				</view>
			</view>
			<view class="bankImage">
				上传凭证<span>(大小不能超过2M)</span>
			</view>

			<view class="bankImage_info">
				<u-upload :fileList="fileList1" @oversize="oversize" @afterRead="afterRead" @delete="deletePic" name="1"
					:maxSize="262144" multiple :maxCount="1">
				</u-upload>
			</view>
			<span class="span" @click="handleClickRecord">充值记录</span>
			<u-button type="success" text="确定提交" @click="GetPut(2)" :disabled="disabled"></u-button>
		</view>

		<view class="fuck" v-show='indexValue===1?true:false'>
			<view class="imgimg">
				<!-- <image src="https://s1.ax1x.com/2022/10/23/xgxD1J.jpg" show-menu-by-longpress="true"></image> -->
			</view>
			<view class="bankMcAll">
				<view class="bankmc2">
					<view class="bankmc_title">
						姓名
					</view>
					<view class="bank_nr">
						<input v-model="CkName" />
					</view>
				</view>
				<view class="bankmc2">
					<view class="bankmc_title">
						支付方式
					</view>
					<view class="bank_nr">
						<input placeholder="例:微信" v-model="Ckkh" disabled="true" />
					</view>
				</view>
				<view class="bankmc2">
					<view class="bankmc_title">
						申请金额
					</view>
					<view class="bank_nr">
						<input v-model="price" />
					</view>
				</view>
			</view>
			<view class="bankImage">
				上传凭证<span>(最多上传4张图片，大小不能超过2M)</span>
			</view>

			<view class="bankImage_info">
				<u-upload :fileList="fileList1" @oversize="oversize" @afterRead="afterRead" @delete="deletePic" name="1"
					:maxSize="262144" multiple :maxCount="1">
				</u-upload>
			</view>
			<span class="span" @click="handleClickRecord">充值记录</span>
			<u-button type="success" text="确定提交" @click="GetPut(2)" :disabled="disabled"></u-button>
		</view>

		<view class="fuck" v-show='indexValue===2?true:false'>
			<view class="bankMcAll">
				<view class="bankmc2">
					<view class="bankmc_title">
						姓名
					</view>
					<view class="bank_nr">
						<input v-model="CkName2" />
					</view>
				</view>
				<view class="bankmc2">
					<view class="bankmc_title">
						电话
					</view>
					<view class="bank_nr">
						<input />
					</view>
				</view>
				<view class="bankmc2">
					<view class="bankmc_title">
						申请金额
					</view>
					<view class="bank_nr">
						<input v-model="price2" />
					</view>
				</view>
			</view>
			<span class="span" @click="handleClickRecord">充值记录</span>
			<u-button type="success" text="跳转支付"></u-button>
		</view>
	</view>
</template>

<script>
	import util from "@/util/index.js"
	export default {
		data() {
			return {
				fileList1: [],
				accountName: '',
				bankAccount: '',
				bankName: '',
				CkName: '',
				cateId: '',
				Ckkh: '',
				price: '',
				fuckMap: ['对公', '扫码', '微信'],
				indexValue: 0,
				disabled: false,
				price2: '',
				CkName2: ''
			}
		},
		beforeDestroy() {
			clearTimeout(this.times);
		},
		onLoad(option) {
			this.cateId = option.id
		},
		methods: {
			getDetail(info) {
				uni.showModal({
					content: info, //模板中提示的内容
					confirmText: '复制内容',
					success: (res) => { //点击复制内容的后调函数
						if (res.confirm) {
							let result
							// #ifndef H5
							//uni.setClipboardData方法就是讲内容复制到粘贴板
							uni.setClipboardData({
								data: info, //要被复制的内容
								success: () => { //复制成功的回调函数
									uni.showToast({ //提示
										title: '复制成功'
									})
								}
							});
							// #endif

							// #ifdef H5 
							let textarea = document.createElement("textarea")
							textarea.value = info
							textarea.readOnly = "readOnly"
							document.body.appendChild(textarea)
							textarea.select() // 选中文本内容
							textarea.setSelectionRange(0, info.length)
							uni.showToast({ //提示
								title: '复制成功'
							})
							result = document.execCommand("copy")
							textarea.remove()
							// #endif
						} else {
							// console.log('取消')
						}
					}
				});
			},
			onCopy: e => {
				uni.showToast({
					title: '复制成功'
				})
			},
			ClickIndex(index) {
				this.CkName = ''
				this.Ckkh = ''
				this.price = ''
				this.fileList1 = []
				if (index == 1) {
					this.Ckkh = '微信支付'
				}
				this.indexValue = index
			},
			handleClickRecord() {
				uni.navigateTo({
					url: '/pages/rechargeRecord/rechargeRecord'
				})
			},
			GetPut(payType) {
				this.disabled = true
				let screenshotTransferUrl = this.fileList1.map(k => k.url).join(",")
				this.$http({
					url: '/offlinePayLog/offlinePayLog',
					data: {
						payType: payType,
						orderNo: "",
						remittanceAccount: this.Ckkh,
						cardholder: this.CkName,
						screenshotTransferUrl: screenshotTransferUrl,
						price: this.price
					}
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '提交成功'
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 10
							})
							this.disabled = false
						}, 2000)
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'error'
						})
						this.disabled = false
					}
				})
			},
			SearchBankInfo() {
				this.$http({
					url: '/offlinePayLog/selectDefaultBank'
				}).then(res => {
					this.accountName = res.data.data.accountName
					this.bankAccount = res.data.data.bankAccount
					this.bankName = res.data.data.bankName
				})
			},
			oversize(e) {
				uni.showToast({
					title: '图片大小已超出限制！',
					icon: "error"
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: util.upload +
						'/rsc/common/upload', // 仅为示例，非真实的接口地址  https://tjxhfarm.com/rsc/common/upload
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(JSON.parse(res.data).data)
							}, 1000)
						}
					});
				})
			},
		},
		mounted() {
			this.SearchBankInfo()
		},
	}
</script>

<style>
	@import './index.css'
</style>
